package com.woniu.his.mms.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniu.his.mms.client.MmsDrugModelClient;
import com.woniu.his.mms.client.param.CreateDrugModelParam;
import com.woniu.his.mms.client.param.ListPageDrugModelParam;
import com.woniu.his.mms.client.result.DrugModelPageResult;
import com.woniu.his.mms.common.MmsResultCode;
import com.woniu.his.mms.service.DrugModelService;
import com.woniu.his.mms.service.dto.DrugModelPageDto;
import com.woniu.his.mms.service.param.CreateDrugModelServiceParam;
import com.woniu.his.mms.service.param.PageDrugModelServiceParam;
import com.woniu.his.result.CommonResultCode;
import com.woniu.his.result.Result;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @version: java version 1.8
 * @Author: Mr tao
 * @description:
 * @date: 2022-11-30 14:19
 */
@Slf4j
@RestController
@RequestMapping("/mms")
public class DrugModelApiImpl implements MmsDrugModelClient {

    @Resource
    private DrugModelService drugModelService;

    /**
     * 创建模板
     * @param createDrugModelParam
     * @return
     */
    @Override
    public Result createDrugModel(CreateDrugModelParam createDrugModelParam) {
       log.info("创建模板:{}",createDrugModelParam);
       //类型转换
        CreateDrugModelServiceParam param = BeanUtil.copyProperties(createDrugModelParam, CreateDrugModelServiceParam.class);
        boolean b=drugModelService.createDrugModel(param);
        return b? Result.getInstance():Result.getInstance().setCode(CommonResultCode.GENERAL_FAIL.getCode()).setMsg("创建失败");
    }

    /**
     * 删除模板
     * @param ids
     * @return
     */
    @Override
    public Result deleteDrugModel(List<Long> ids) {
       log.info("删除模板:{}",ids);
       boolean b = drugModelService.deleteDrugModel(ids);
        return b? Result.getInstance():Result.getInstance().setCode(CommonResultCode.GENERAL_FAIL.getCode()).setMsg("删除失败");
    }

    /**
     * 更新模板
     * @param createDrugModelParam
     * @return
     */
    @Override
    public Result updateDrugModel(CreateDrugModelParam createDrugModelParam) {
        log.info("更新模板:{}",createDrugModelParam);
        CreateDrugModelServiceParam param = BeanUtil.copyProperties(createDrugModelParam, CreateDrugModelServiceParam.class);
        boolean b=drugModelService.updateDrugModel(param);
        return b? Result.getInstance():Result.getInstance().setCode(CommonResultCode.GENERAL_FAIL.getCode()).setMsg("更新失败");
    }

    /**
     * 分页查询
     * @param pageDrugModelParam
     * @return
     */
    @Override
    public Result<DrugModelPageResult> listPageDrugModel(ListPageDrugModelParam pageDrugModelParam) {
        log.info("分页查询:{}",pageDrugModelParam);
        PageDrugModelServiceParam param=BeanUtil.copyProperties(pageDrugModelParam,PageDrugModelServiceParam.class);
        DrugModelPageDto dto =   drugModelService.listPageDrugModel(param);
        if(dto==null) return null;
        DrugModelPageResult drugModelPageResult = BeanUtil.copyProperties(dto, DrugModelPageResult.class);
        return Result.getInstance(DrugModelPageResult.class).setData(drugModelPageResult);
    }


}
